#{extends 'backend_main.html' /}
<div class="x-nav">
    <span class="layui-breadcrumb"><a>首页</a><a>管理员管理</a><a><cite>权限列表</cite></a></span>
    <a class="layui-btn layui-btn-sm" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane">
          <input class="layui-input" placeholder="权限名" name="menu_name" id="menu_name"  lay-verify="required|menu_name" >
          <input class="layui-input" placeholder="访问地址" name="access_url" id="access_url" lay-verify="required|access_url">
          <button class="layui-btn"  lay-submit="" lay-filter="add"><i class="layui-icon"></i>增加</button>
        </form>
      </div>
      <xblock>
        <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
        <span class="x-right" style="line-height:40px">共有数据：${pageBean?.totalCount} 条</span>
      </xblock>
      <table class="layui-table">
        <thead>
          <tr>
            <th>
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th>ID</th>
            <th>权限名称</th>
            <th>权限规则</th>
            <th>操作</th>
        </thead>
        <tbody>
        #{list pageBean?.page}
          <tr>
            <td>
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='${_?.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td>${_?.id}</td>
            <td>${_?.menu_name}</td>
            <td>${_?.access_url}</td>
            <td class="td-manage">
              <a title="编辑"  onclick="x_admin_show('编辑','/SystemCenter/adminRuleEdit?v=view&id=${_?.id}')" href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs">
                编辑
              </a>
            </td>
          </tr>
        #{/list}
        </tbody>
      </table>
    #{page currPage:pageBean?.currPage,totalCount:pageBean?.totalCount,pageSize:pageBean?.pageSize,theme:2,style:1 /}
    </div>
    <script>
        layui.use(['laydate','form'], function(){
            var $ = layui.jquery,form = layui.form,layer = layui.layer;
            //自定义验证规则
            form.verify({
                menu_name: function(value){
                    if(value.length < 2){
                        return '权限名至少得2个字符啊';
                    }
                },access_url: function(value){
                    if(value.length < 2){
                        return '访问地址至少得2个字符啊';
                    }
                }
            });
          //监听提交
          form.on('submit(add)', function(data){
              console.log(JSON.stringify(data));
              //发异步，把数据提交给php
              $.ajax({
                  type:"POST",                      //请求类型
                  url:"/SystemCenter/insert",           //URL
                  data:data.field,   //传递的参数
                  dataType:"json",                 //返回的数据类型
                  success:function(data){          //data就是返回的json类型的数据
                      layer.alert(data.msg, {icon: 6},function () {
                          window.location.reload();
                      });
                  }
              });
              return false;
          });
      });
      function delAll () {
        var data = tableCheck.getData();
          if(data==""){
              layer.msg("请先选择要删除的条目");
              return;
          }
        layer.confirm('确认要删除吗？'+data,function(index){
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type:"POST",                      //请求类型
                url:"/SystemCenter/adminRuleEdit?v=delete",                 //URL
                data:"ids="+data,                  //传递的参数
                dataType:"json",                 //返回的数据类型
                success:function(data){          //data就是返回的json类型的数据
                    console.log(data);
                    window.location.reload();
                },
                error:function(data){
                }
            });
        });
      }
    </script>
